#ifndef VFlowLayoutTest_H
#define VFlowLayoutTest_H

#include "ui_VFlowLayoutTest.h"
#include "../../VCommon/VFlowLayout.h"

///////////////////////////////////////////////////////////////////////////////

class VLineEdit : public QLineEdit
{
	Q_OBJECT
	
public:
	VLineEdit() 
	{
		setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
		setTextMargins(0,0,0,0);
		setContentsMargins(0,0,0,0);
		//setFrame(false);

		connect(
			this,SIGNAL( textChanged(const QString &) ),
			this,SLOT( slotTextChanged() )
		);

		slotTextChanged();
	}

	void setFontPointSize(int v) {
		QFont font = this->font();
		font.setPointSize(v);
		setFont(font);
	}

/****
	virtual QSize	sizeHint() const
	{
		QSize	size = QLineEdit::sizeHint();
		size.setWidth(minimumSize().width());
		return size;
	}

	virtual QSize minimumSize() const
	{
		QSize size = QLineEdit::minimumSize();
		size.setWidth(calcWidth());
		return size;
	}
************/
	
private slots:
	void slotTextChanged()
	{
		QSize size = sizeHint();
			size.setWidth(calcWidth());

		setMaximumSize(size);
		setMinimumSize(size);
	}
	
	int calcWidth() const
	{
		QFontMetrics fm = fontMetrics();
		return fm.width(displayText()) + 10;
	}
};

///////////////////////////////////////////////////////////////////////////////

class VTextEdit : public QTextEdit
{
	Q_OBJECT
	
public:
	VTextEdit()
	{
		//QTextDocument *p = document();
		setAcceptRichText(true);
	
		//connect(
		//	document(),SIGNAL( contentsChanged() ),
		//	this,SLOT( slotContentsChanged() )
		//);

		connect(
			this,SIGNAL( textChanged() ),
			this,SLOT( slotContentsChanged() )
		);
		
		slotContentsChanged();
	}
	
private slots:	
	void slotContentsChanged()
	{
		int height = document()->size().height();
		if (height < 10) {
			height = 10;
		}
		
		QSize size = sizeHint();
			size.setHeight(height + 2);

		setMaximumSize(size);
		setMinimumSize(size);
	
	
	
		//qDebug() << document()->size();
//int dd = document()->textWidth();
//QTextBlock tb = document()->firstBlock();
//int lc = tb.lineCount();

/*
		QSize size = sizeHint();
			size.setWidth(document()->textWidth());

		setMaximumSize(size);
		setMinimumSize(size);
*/		
	}
};

///////////////////////////////////////////////////////////////////////////////

class VLabel : public QLabel
{
	Q_OBJECT

public:
	~VLabel()
	{
	
	}

	virtual int	heightForWidth(int w) const
	{
		return QLabel::heightForWidth(w);
	}
	
	virtual QSize	minimumSizeHint() const
	{
		return QLabel::minimumSizeHint();
	}
	
	virtual QSize	sizeHint() const
	{
		return QLabel::sizeHint();
	}
};

///////////////////////////////////////////////////////////////////////////////

class Window : public QWidget
{
	Q_OBJECT

public:
	Window();
};

///////////////////////////////////////////////////////////////////////////////

class VFlowLayoutTest : public QMainWindow
{
	Q_OBJECT

public:
	VFlowLayoutTest(QWidget *parent = 0, Qt::WFlags flags = 0);
	~VFlowLayoutTest();

private:
	Ui::VFlowLayoutTestClass ui;
};

///////////////////////////////////////////////////////////////////////////////

#endif
